﻿// JScript 文件

//function showDlg()
//{
//    var dlg = new CtnDlgCtrl();
//    dlg.init(
//    {title:"标题",
//    url:"../mainmap.htm", 
// //   content:"中华人民共和国万岁！中华人民共和国万岁！中华人民共和国万岁！中华人民共和国万岁！",
//    bmove:true,
//    bmodal:false,
////    iconcss:CtnDlgCtrl.icon.WARNING,
//    width:200,height:300,
//    arrbtn: [{text:"确定", onClick:function(){alert("确定")}},{text:"取消", onClick:function(){alert("取消")}}]
//    });
//    dlg.open();
//}

CtnDlgCtrl.arrDlg       = new Array();    //用于保存所有的Dlg
CtnDlgCtrl.elemMove     = null; //拖动元素
CtnDlgCtrl.elemResize   = null; //拉伸元素
CtnDlgCtrl.elemBar      = null; //拉伸元素
CtnDlgCtrl.dlgIdx       = 0;    //对话框的总索引号
CtnDlgCtrl.zIndex       = 3000;    //最高层的z-index;
CtnDlgCtrl.icon         = {
    WARNING: "warning",
    ERROR: "error",
    MSG: "msg",
    QUESTION: "question",
    LOADING: "loading",
    NONE: "none"
}

CtnDlgCtrl.bind         = bind_DC;
CtnDlgCtrl.unbind       = unbind_DC;
CtnDlgCtrl.getEventXY   = getEventXY_DC;
CtnDlgCtrl.getMoveXY    = getMoveXY_DC;
CtnDlgCtrl.floatDlg     = floatDlg_DC;
CtnDlgCtrl.onMoveDlg     = onMoveDlg_DC;
CtnDlgCtrl.moveDlg     = moveDlg_DC;
CtnDlgCtrl.mouseup     = mouseup_DC;
CtnDlgCtrl.adjustBg     = adjustBg_DC;
CtnDlgCtrl.adjustBar    = adjustBar_DC;
CtnDlgCtrl.resizeDlg    = resizeDlg_DC;
CtnDlgCtrl.getDocWidth  = getDocWidth_DC;
CtnDlgCtrl.getDocHeight = getDocHeight_DC;

function CtnDlgCtrl()
{
    this.title      = null; //标题
    this.width      = null;   //宽度
    this.height     = null;   //高度
    this.minwidth   = 150;  //最小宽度
    this.minheight  = 70;  //最小高度
    this.left       = null;   //Left
    this.dlgtop     = null;   //Top
    this.url        = null; //iframe地址
    this.content    = null; //内容(与url互异)
    this.bmodal     = true; //是否模态
    this.bresize    = true;
//    this.arrresize  = [1,1,1,1,1,1,1,1];
    this.bmove      = true; //是否可移动
    this.bfloat     = true; //是否浮动
    this.bout       = false;    //是否越界
    this.bclose     = true; //是否关闭
    this.bmax       = true; //是否最大化
    this.bmin       = true; //是否最小化
    this.iconcss    = CtnDlgCtrl.icon.NONE; //标志图标的Css
    this.css        = "dlgctrl"; //主样式    this.srcwin     = null;

    this.arrbtn     = new Array();
//    this.target     = window;   //窗口对象
//    this.parent     = null;//iframe访问父级
//    this.dlgstyle   = null;
//    this.titlestyle = null;
//    this.cntstyle   = null;
    
    this.element    = null;//对话框元素
    this.wnd        = null;//iframe子窗体Window
    this.init       = init_DC;  //初始化参数    this.reset      = reset_DC;

    this.open       = open_DC;  //打开窗口
    this.close      = close_DC; //关闭窗口
    this.maximize   = maximize_DC;
    this.restore    = restore_DC;
    this.minimize   = minimize_DC;
//    this.show       = show_DC;
//    this.hide       = null;
    this.create     = create_DC;    //创建窗口
    this.createMask = createMask_DC;    //创建模态遮盖
    this.createMove = createMove_DC;    //创建拖动层
    this.createBg   = createBg_DC;  //创建窗口背景，用于遮盖select
    this.createResize   = createResize_DC;  //创建拉伸层
    this.createEvent    = createEvent_DC;   //创建事件遮盖,解决iframe上事件响应问题
    this.createBar      = createBar_DC;
    
    this.onBtnClick     = onBtnClick_DC;
    this.onClose        = null;
    this.onMaximize     = null;
    this.onRestore      = null;
    this.onMinimize     = null;
    this.onResize       = null; //拉伸后
    
}

function init_DC(params)
{
    if(typeof(params) != 'object')
    {
        return;
    }
    for (var key in params)
    {
        //key = key.toLowerCase();
        if (key != "top")
        {
            this[key] = params[key];
        }
        else
        {
            this['dlgtop'] = params[key];
        }
    }
}

function reset_DC(params)
{
    this.init(params);
    if (this.url)
    {
        this.element.elemFrm.src = this.url;
    }
    else
    {
        this.element.elemBody.innerHTML = this.content;
    }
    this.element.elemTitle.innerHTML = this.title;
}

function open_DC()
{
    this.create();
	//调整大小和位置
    if (this.width != null && this.width > this.minwidth)
	{
	    this.element.style.width = this.width + "px";
	}
	else
	{
	    this.element.style.width = this.minwidth + "px";
	}
	this.element.elemBody.style.width = (parseInt(this.element.style.width) - this.element.lrWidth) + "px";
	
	if (this.height != null && this.height >= this.minheight)
	{
	    this.element.elemBody.style.height = (this.height - this.element.tbHeight) + "px";
	}
	else if ((this.height != null && this.height < this.minheight)
	    || (this.height == null && this.element.offsetHeight < this.minheight))
	{
	    this.element.elemBody.style.height = (this.minheight - this.element.tbHeight) + "px";
	}
	else if (this.height != null)
	{
	    this.element.elemBody.style.height = this.height + "px";
	}
	
	if (this.left == null)
	{
        this.element.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.element.offsetWidth) / 2) + "px";
    }
    else
    {
        this.element.style.left = this.left + "px";
    }
    //if (this.top == null)
    if (this.dlgtop == null)
	{
        this.element.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - this.element.offsetHeight) / 2) + "px";
    }
    else
    {
        this.element.style.top = this.dlgtop + "px";
    }
    //设置离窗口的位置
    this.element.winX = parseInt(this.element.style.left) - document.documentElement.scrollLeft;
    this.element.winY = parseInt(this.element.style.top) - document.documentElement.scrollTop;
    
    CtnDlgCtrl.adjustBg(this.element);
    if (this.bresize)
    {
        CtnDlgCtrl.adjustBar(this.element);
    }
    CtnDlgCtrl.bind(document, "mouseup", CtnDlgCtrl.mouseup);
    if (this.bfloat)
    {
        window.onscroll = CtnDlgCtrl.floatDlg;
    }
}

function close_DC()
{
    if (this.onClose)
    {
        var flag = this.onClose(this);
        if (flag == false)
        {
            return;
        }
    }
    elem = this.element;

    var arrDlg = CtnDlgCtrl.arrDlg;
    for (var i = 0; i < arrDlg.length; i++)
    {
        if (arrDlg[i] == elem)
        {
            arrDlg.splice(i, 1);
            break;
        }
    }
    if(this.bmodal)
    {
        CtnDlgCtrl.elemMask.num--;
        if (CtnDlgCtrl.elemMask.num < 1)
        {
            CtnDlgCtrl.elemMask.style.display = "none";
        }
    }
    if (this.bmove)
    {
        elem.elemMove.parentNode.removeChild(elem.elemMove);
    }
    if (this.bresize)
    {
        for (var i = 0; i < elem.arrBar.length; i++)
        {
            elem.arrBar[i].parentNode.removeChild(elem.arrBar[i]);
        }
    }
    elem.elemBg.parentNode.removeChild(elem.elemBg);
    var __ELEM = elem;
    setTimeout(function(){__ELEM.parentNode.removeChild(__ELEM)},0);
}

function maximize_DC()
{
    elemDlg = this.element;
    elemDlg.lastStatus = "max";
    elemDlg.elemMax.style.display = "none";
    elemDlg.elemRst.style.display = "";
    //记录最后位置
    elemDlg.lastX = elemDlg.winX;
    elemDlg.lastY = elemDlg.winY;
    elemDlg.lastWidth = elemDlg.offsetWidth;
    elemDlg.lastHeight = elemDlg.offsetHeight;
    
    elemDlg.winX = 0;
    elemDlg.winY = 0;
    elemDlg.style.left = document.documentElement.scrollLeft + "px";
    elemDlg.style.top = document.documentElement.scrollTop + "px";
    elemDlg.style.width = (document.documentElement.clientWidth -22) + "px";
    
    elemDlg.elemBody.style.width = (parseInt(elemDlg.style.width) - elemDlg.lrWidth) + "px";
    
    elemDlg.elemBody.style.height = (document.documentElement.clientHeight - elemDlg.tbHeight - 4) + "px";
    //调整背景
    CtnDlgCtrl.adjustBg(elemDlg);
    if (this.bresize)
    {
        CtnDlgCtrl.adjustBar(elemDlg);
    }
    
    if(elemDlg.object.onMaximize)
    {
        elemDlg.object.onMaximize(elemDlg.object);
    }
    //拉伸后，响应事件
    if(elemDlg.object.onResize)
    {
        elemDlg.object.onResize(elemDlg.object);
    }
}
function minimize_DC()
{
    var elemDlg = this.element;
    //隐藏最小按纽
    elemDlg.elemMin.style.display = "none";
    elemDlg.elemMax.style.display = "none";
    elemDlg.elemRst.style.display = "";
    //记录最后位置
    if (elemDlg.lastStatus != "max")
    {
        elemDlg.lastX = elemDlg.winX;
        elemDlg.lastY = elemDlg.winY;
        elemDlg.lastWidth = elemDlg.offsetWidth;
        elemDlg.lastHeight = elemDlg.offsetHeight;
    }
    //隐藏主体和button
    elemDlg.childNodes[1].style.display = "none";
    elemDlg.elemBtn.style.display = "none";
    //调整位置
    elemDlg.style.width = "100px";
    elemDlg.style.top = (document.documentElement.scrollTop + document.documentElement.clientHeight - elemDlg.firstChild.offsetHeight - 6) + "px";
    elemDlg.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - elemDlg.offsetWidth) / 2) + "px";
    //调整背景
    CtnDlgCtrl.adjustBg(elemDlg);
    if (this.bresize)
    {
        CtnDlgCtrl.adjustBar(elemDlg);
    }
    //调整离窗口的位置
    elemDlg.winX = parseInt(elemDlg.style.left) - document.documentElement.scrollLeft;
    elemDlg.winY = parseInt(elemDlg.style.top) - document.documentElement.scrollTop;
    
    if(elemDlg.object.onMinimize)
    {
        elemDlg.object.onMinimize(elemDlg.object);
    }
    //拉伸后，响应事件
    if(elemDlg.object.onResize)
    {
        elemDlg.object.onResize(elemDlg.object);
    }
}
function restore_DC()
{
    var elemDlg = this.element;
     //隐藏最小按纽
    if (elemDlg.lastStatus == "max" && elemDlg.elemMin.style.display == "none")
    {
        elemDlg.elemMin.style.display = "";
        elemDlg.winX = 0;
        elemDlg.winY = 0;
        elemDlg.style.width = (document.documentElement.clientWidth -22) + "px";
    }
    else
    {
        elemDlg.elemRst.style.display = "none";
        elemDlg.elemMax.style.display = "";
        elemDlg.elemMin.style.display = "";
        elemDlg.lastStatus = null;
        //还原最后位置
        elemDlg.winX = elemDlg.lastX;
        elemDlg.winY = elemDlg.lastY;
        elemDlg.style.width = elemDlg.lastWidth + "px";
        elemDlg.elemBody.style.height = (elemDlg.lastHeight - elemDlg.tbHeight) + "px";
    }
    
    elemDlg.elemBody.style.width = (parseInt(elemDlg.style.width) - elemDlg.lrWidth) + "px";
    //
    elemDlg.childNodes[1].style.display = "";
    elemDlg.elemBtn.style.display = "";
    CtnDlgCtrl.floatDlg();
    if(elemDlg.object.onResize)
    {
        elemDlg.object.onResize(elemDlg.object);
    }
    //拉伸后，响应事件
    if(elemDlg.object.onResize)
    {
        elemDlg.object.onResize(elemDlg.object);
    }
}
function createMask_DC()
{
    //创建模态遮盖
    var elemMask = document.createElement("div");
    //elemMask.style.position = "absolute";
    elemMask.className = "dlgctrl_position";
    elemMask.style.left = "0";
    elemMask.style.top = "0";
    elemMask.style.width = CtnDlgCtrl.getDocWidth() + "px";
    elemMask.style.height = CtnDlgCtrl.getDocHeight() + "px";
    elemMask.style.backgroundColor = "black";
    elemMask.style.filter = "alpha(opacity=5)";
    elemMask.style.MozOpacity = "0.05";
    //创建iframe 用于遮盖select
    var elemFrm = document.createElement("iframe");
    elemFrm.frameborder = "0";
    elemFrm.marginwidth = "0";
    elemFrm.marginheight = "0";
    elemFrm.src = "about:blank";
    elemFrm.style.width = "100%";
    elemFrm.style.height = "100%";
    elemFrm.style.filter = "alpha(opacity=0)";
    elemFrm.style.MozOpacity = "0";
    elemMask.appendChild(elemFrm);
    return elemMask;
}

function createMove_DC()
{
    var elemMove = document.createElement("div");
    elemMove.style.position = "absolute";
    elemMove.style.filter = "alpha(opacity=20)";
    elemMove.style.MozOpacity = "0.2";
    var vHtml = "";
    vHtml += '<div class="tl">';
    vHtml += '<div class="tr">';
    vHtml += '<div class="mc">';
    vHtml += '<div class="tool">';
    if (this.bmin)
    {
        vHtml += '<span class="min"></span>';
    }
    if (this.bmax)
    {
        vHtml += '<span class="max"></span>';
    }
    if (this.bclose)
    {
        vHtml += '<span class="close"></span>';
    }
    vHtml += '</div>'
    vHtml += '<span class="title">' + this.title + '</span>';
    vHtml += '</div></div></div>';
    vHtml += '<ul></ul>';
    elemMove.innerHTML = vHtml;
}

function createBg_DC()
{
    var elemBg = document.createElement("div");
    //elemBg.style.position = "absolute";
    elemBg.className = "dlgctrl_position";
    //创建iframe 用于遮盖select
    var elemFrm = document.createElement("iframe");
    elemFrm.frameborder = "0";
    elemFrm.marginwidth = "0";
    elemFrm.marginheight = "0";
    elemFrm.src = "about:blank";
    elemFrm.style.width = "100%";
    elemFrm.style.height = "100%";
    elemFrm.style.border = "0";
    elemBg.appendChild(elemFrm);
    return elemBg;
}

function createResize_DC()
{
    //1px dashed #3B5A82
    var elemResize = document.createElement("div");
    elemResize.style.position = "absolute";
    elemResize.style.border = "1px dashed #3B5A82";
//    elemResize.style.filter = "alpha(opacity=0)";
//    elemResize.style.MozOpacity = "0";
    return elemResize;
}

function createEvent_DC()
{
    var elemEvent = document.createElement("div");
    elemEvent.style.position = "absolute";
    elemEvent.style.filter = "alpha(opacity=0)";
    elemEvent.style.MozOpacity = "0";
    elemEvent.style.left = "0";
    elemEvent.style.top = "0";
    elemEvent.style.width = CtnDlgCtrl.getDocWidth() + "px";
    elemEvent.style.height = CtnDlgCtrl.getDocHeight() + "px";
    return elemEvent;
}
function createBar_DC()
{
    var barSize = 2;//拉动边大小
    //八位Bar的left,top,width,height移动方向
    var arrFlag = new Array(
        [0, 1, 0,-1],
        [0, 1, 1,-1],
        [0, 0, 1, 0],
        [0, 0, 1, 1],
        [0, 0, 0, 1],
        [1, 0,-1, 1],
        [1, 0,-1, 0],
        [1, 1,-1,-1]);
    //八位Bar鼠标
    var arrCursor = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'];
   	//创建Bar
   	var elem  = document.createElement("div");
   	with(elem.style)
   	{
	    position = "absolute";
	    backgroundColor = "black";
//	    margin = "0";
//	    padding = "0";
	    fontSize = barSize + "px";
	    width = barSize + "px";
	    height = barSize + "px";
	    filter = "alpha(opacity=0)";
	    MozOpacity = "0";
	}
	var zIndex1 = ++CtnDlgCtrl.zIndex;
	var zIndex2 = ++CtnDlgCtrl.zIndex;
	this.element.arrBar = new Array();
	for (var i = 0; i < 8; i++)
	{
	    var elemBar = elem.cloneNode(true);
	    if (i%2)
	    {
	        elemBar.style.width = barSize*2 + "px";
	        elemBar.style.height = barSize*2 + "px";
	        elemBar.style.zIndex = zIndex2;
	    }
	    else
	    {
	        elemBar.style.zIndex = zIndex1;
	    }
	    document.body.appendChild(elemBar);
	    elemBar.style.cursor = arrCursor[i] + "-resize";
	    elemBar.arrFlag = arrFlag[i];
	    elemBar.elemDlg = this.element;
	    elemBar.onmousedown = function()
	    {
	        CtnDlgCtrl.elemBar = this;
	        var elemResize = CtnDlgCtrl.elemResize;
	        var elemDlg = this.elemDlg;
	        elemResize.arrBar = elemDlg.arrBar;
	        elemResize.style.left = parseInt(elemDlg.style.left) + "px";
	        elemResize.style.top = parseInt(elemDlg.style.top) + "px";
	        elemResize.style.width = elemDlg.offsetWidth + "px";
	        elemResize.style.height = elemDlg.offsetHeight + "px";
	        elemResize.style.zIndex = parseInt(elemDlg.style.zIndex) + 2;
	        elemResize.style.display = "";
	        CtnDlgCtrl.elemEvent.style.zIndex = parseInt(elemDlg.style.zIndex) + 1;
	        CtnDlgCtrl.elemEvent.style.display = "";
	        CtnDlgCtrl.bind(document, "mousemove", CtnDlgCtrl.resizeDlg);
	    };
	    this.element.arrBar.push(elemBar);
	}
}
function create_DC()
{
    var elemDlg = document.createElement("div");
    elemDlg.className = this.css;
    elemDlg.style.position = "absolute";
    var vHtml = "";
    vHtml += '<div class="tl">';
    vHtml += '<div class="tr">';
    vHtml += '<div class="tc">';
    vHtml += '<div class="header" style="-moz-user-select: none;">';
    vHtml += '<div class="tool close"></div>';
    vHtml += '<div class="tool max"></div>';
    vHtml += '<div class="tool restore"></div>';
    vHtml += '<div class="tool min"></div>';
    vHtml += '<span class="title">' + this.title + '</span>';
    vHtml += '</div>';
    vHtml += '</div></div></div>';
    vHtml += '<div class="ml">';
    vHtml += '<div class="mr">';
    vHtml += '<div class="mc">';
    vHtml += '<div class="icon ' + this.iconcss + '">&nbsp;</div>';
    vHtml += '<div class="body"></div>';
    vHtml += '</div></div></div>';
    vHtml += '<div class="bl">';
    vHtml += '<div class="br">';
    vHtml += '<div class="bc">';
    vHtml += '<div class="btn"></div>';
    vHtml += '</div></div></div>';
    elemDlg.innerHTML = vHtml;
    //相互存储，方便访问
	this.element = elemDlg;
	elemDlg.object = this;
	CtnDlgCtrl.arrDlg.push(elemDlg);
    //存储一些常用元素
    elemDlg.elemHeader = elemDlg.firstChild.firstChild.firstChild.firstChild;
    elemDlg.elemHeader.elemDlg = elemDlg;
    elemDlg.elemHeader.onmousedown = function (evt)
    {
        evt = evt||window.event;
        var elem = evt.target || evt.srcElement;
        //如果不是右键和控制按纽
        if (elemDlg.object.bmove
            &&(evt.button != 2)
            &&(elem != this.elemDlg.elemClose)
            &&(elem != this.elemDlg.elemMax)
            &&(elem != this.elemDlg.elemRst)
            &&(elem != this.elemDlg.elemMin)
            )
        {
            CtnDlgCtrl.onMoveDlg(this.elemDlg, evt);
        }
    }
    elemDlg.elemHeader.onmouseup = function (evt)
    {
        evt = evt||window.event;
        var elem = evt.target || evt.srcElement;
        switch (elem)
        {
            case this.elemDlg.elemClose: this.elemDlg.object.close();break;
            case this.elemDlg.elemMax: this.elemDlg.object.maximize();break;
            case this.elemDlg.elemRst: this.elemDlg.object.restore();break;
            case this.elemDlg.elemMin: this.elemDlg.object.minimize();break;
            default:break;
        }
    }
    elemDlg.elemHeader.ondblclick = function (evt)
    {
        if (!this.elemDlg.object.bmax)
        {
            return;
        }
        if (this.elemDlg.elemMax.style.display != "none")
        {
            this.elemDlg.object.maximize();
        }
        else
        {
            this.elemDlg.object.restore();
        }
    }
    elemDlg.elemClose = elemDlg.elemHeader.firstChild;
    elemDlg.elemClose.onmouseover = function(){this.className = "tool close-over";}
    elemDlg.elemClose.onmouseout = function(){this.className = "tool close";}
    if (!this.bclose)
    {
        elemDlg.elemClose.style.display = "none";
    }
    elemDlg.elemMax = elemDlg.elemClose.nextSibling;
    elemDlg.elemMax.onmouseover = function(){this.className = "tool max-over";}
    elemDlg.elemMax.onmouseout = function(){this.className = "tool max";}
    if (!this.bmax)
    {
        elemDlg.elemMax.style.display = "none";
    }
    elemDlg.elemRst = elemDlg.elemMax.nextSibling;
    elemDlg.elemRst.onmouseover = function(){this.className = "tool restore-over";}
    elemDlg.elemRst.onmouseout = function(){this.className = "tool restore";}
    elemDlg.elemRst.style.display = "none";//先隐藏还原按纽
    elemDlg.elemMin = elemDlg.elemRst.nextSibling;
    elemDlg.elemMin.onmouseover = function(){this.className = "tool min-over";}
    elemDlg.elemMin.onmouseout = function(){this.className = "tool min";}
    if (!this.bmin)
    {
        elemDlg.elemMin.style.display = "none";
    }
    elemDlg.elemTitle = elemDlg.elemMin.nextSibling;
    elemDlg.elemIcon = elemDlg.childNodes[1].firstChild.firstChild.firstChild;
    elemDlg.elemBody = elemDlg.elemIcon.nextSibling;
    elemDlg.elemBtn = elemDlg.lastChild.firstChild.firstChild.firstChild;
    elemDlg.elemBg = this.createBg();
    //创建模态遮盖层(通用一份)
    if (!CtnDlgCtrl.elemMask)
    {
        CtnDlgCtrl.elemMask = this.createMask();
        CtnDlgCtrl.elemMask.style.display = "none";
        CtnDlgCtrl.elemMask.num = 0;    //使用个数
        document.body.appendChild(CtnDlgCtrl.elemMask);
        CtnDlgCtrl.elemMask.style.zIndex = ++CtnDlgCtrl.zIndex;
    }
    if (this.bmodal)
    {
        CtnDlgCtrl.elemMask.style.display = "";
        CtnDlgCtrl.elemMask.num++;
    }
    //创建事件遮盖层(通用一份)
    if (!CtnDlgCtrl.elemEvent)
    {
        CtnDlgCtrl.elemEvent = this.createEvent();
        CtnDlgCtrl.elemEvent.style.display = "none";
        CtnDlgCtrl.elemEvent.style.backgroundColor="black";
        document.body.appendChild(CtnDlgCtrl.elemEvent);
    }
    //拉伸层
    if (!CtnDlgCtrl.elemResize)
    {
        var elemResize = this.createResize();
        elemResize.style.display = "none";
        document.body.appendChild(elemResize);
        CtnDlgCtrl.elemResize = elemResize;
    }
    //创建背景遮盖层
    elemDlg.elemBg = this.createBg();
    document.body.appendChild(elemDlg.elemBg);
    elemDlg.elemBg.style.zIndex = ++CtnDlgCtrl.zIndex;
    document.body.appendChild(elemDlg);
    elemDlg.style.zIndex = ++CtnDlgCtrl.zIndex;
    ++CtnDlgCtrl.zIndex;//预留给事件遮盖层
    //创建移动层
    if (this.bmove)
    {
        elemDlg.elemHeader.style.cursor = "move"; 
        var elemMove = elemDlg.cloneNode(true);
        elemMove.removeChild(elemMove.lastChild);
        elemMove.removeChild(elemMove.lastChild);
        elemUl = document.createElement("ul");
        elemUl.className="move";
        elemMove.appendChild(elemUl);
        elemMove.style.filter = "alpha(opacity=50)";
        elemMove.style.MozOpacity = "0.5";
        elemMove.style.display = "none";
        document.body.appendChild(elemMove);
        elemMove.elemDlg = elemDlg;
        elemDlg.elemMove = elemMove;
    }
    ++CtnDlgCtrl.zIndex;//预留给移动层
    if (this.bresize)
    {
        this.createBar();
    }
    ++CtnDlgCtrl.zIndex;//预留给拉伸层用
    //创建按纽
    if (this.arrbtn.length > 0)
	{
	    this.minheight = 92;
	    elemDlg.elemBtn.objDlg = this;  //存储对象
	    var vHtml = "";
	    for (var i = 0; i < this.arrbtn.length; i++)
	    {
	        vHtml += '<input type="button" class="button" value="' + this.arrbtn[i].text + '" onclick="this.parentNode.objDlg.onBtnClick(' + i + ')" />'
	    }
	    elemDlg.elemBtn.innerHTML = vHtml;
	}
	//计算top,bottom和body边框
//	elemDlg.tbHeight = elemDlg.firstChild.offsetHeight + elemDlg.lastChild.offsetHeight + 2;
	elemDlg.tbHeight = 24 + elemDlg.lastChild.offsetHeight + 2;//IE中无法取得浮动元素的offsetHeight
	if (elemDlg.tbHeight > this.minHeight)
	{
	    this.minHeight = elemDlg.tbHeight;
	}
	//两边宽度
	elemDlg.lrWidth = 6*2 + 2;
	if (this.iconcss != CtnDlgCtrl.icon.NONE)
	{
	    elemDlg.lrWidth += elemDlg.elemIcon.offsetWidth + 12;
	}
    //创建内容
    if (this.url)
    {
        elemDlg.elemBody.innerHTML = '<iframe src="' + this.url + '" class="frm" frameborder="0" marginwidth="0" marginheight="0"></iframe>';
        this.wnd = elemDlg.elemBody.firstChild.contentWindow;
        this.wnd.m_dlg = this;
    }
    else
    {
        elemDlg.elemBody.innerHTML = this.content;
    }
}

function onBtnClick_DC(idx)
{
    for (var i = 0; i < this.arrbtn.length; i++)
    {
        if (idx == i && this.arrbtn[i].onClick)
        {
            this.arrbtn[i].onClick(this);
        }
    }
}

//事件绑定
function bind_DC(elem, src, target)
{
	if (elem.attachEvent)
	{
		elem.attachEvent("on" + src, target);
	}
	else if (elem.addEventListener)
	{
		elem.addEventListener(src, target, true);
	}
}
//取消事件绑定
function unbind_DC(elem, src, target)
{
	if (elem.detachEvent)
	{
		elem.detachEvent("on" + src, target);
	}
	else if (elem.removeEventListener)
	{
		elem.removeEventListener(src, target, true);
	}
}

function getEventXY_DC(evt)
{
	var pos = {};
	if(!document.all)
	{
		pos = {x:evt.pageX, y:evt.pageY};
	}
	else
	{
		pos = {x:document.documentElement.scrollLeft + evt.clientX, y:document.documentElement.scrollTop+evt.clientY};
	}
	return pos;
}

function getMoveXY_DC(evt, elem)
{
	var pos = getEventXY_DC(evt);
	var tmp = {x:pos.x - parseInt(elem.style.left), y:pos.y - parseInt(elem.style.top)};
	return tmp;
}
function floatDlg_DC()
{
    var arrDlg = CtnDlgCtrl.arrDlg;
    for (var i = 0; i < arrDlg.length; i++)
    {
        arrDlg[i].style.left = (arrDlg[i].winX + document.documentElement.scrollLeft) + "px";
        arrDlg[i].style.top = (arrDlg[i].winY + document.documentElement.scrollTop) + "px";
        CtnDlgCtrl.adjustBg(arrDlg[i]);
        if (arrDlg[i].object.bresize)
        {
            CtnDlgCtrl.adjustBar(arrDlg[i]);
        }
	}
}

function onMoveDlg_DC(elemDlg, evt)
{
    //调出事件遮盖层
    CtnDlgCtrl.elemEvent.style.zIndex = parseInt(elemDlg.style.zIndex) + 1;
    CtnDlgCtrl.elemEvent.style.display = "";
    //拷贝出一个移动层
    var elemMove = elemDlg.elemMove;
    elemMove.style.zIndex = parseInt(elemDlg.style.zIndex) + 2;
    elemMove.style.width = elemDlg.offsetWidth + "px";
//    elemMove.lastChild.style.height = (elemDlg.offsetHeight - elemDlg.firstChild.offsetHeight) + "px";
    if (elemDlg.offsetHeight > 24)
    {
        elemMove.lastChild.style.height = (elemDlg.offsetHeight - 24) + "px";
    }
    else
    {
        elemMove.lastChild.style.height = "0px";
    }
    //隐藏对话框
    elemMove.style.left = parseInt(elemDlg.style.left) + "px";
    elemMove.style.top = parseInt(elemDlg.style.top) + "px";
    elemMove.style.display = "";
    elemDlg.elemBg.style.display = "none";
    elemDlg.style.display = "none";
    elemMove.mouseX = evt.clientX;
    elemMove.mouseY = evt.clientY;

    CtnDlgCtrl.elemMove = elemMove;
    CtnDlgCtrl.bind(document, "mousemove", CtnDlgCtrl.moveDlg);
}

function moveDlg_DC(evt)
{
    evt = evt||window.event;
    if (CtnDlgCtrl.elemMove)
    {
        var elemMove = CtnDlgCtrl.elemMove;
        var objDlg = elemMove.elemDlg.object;
        var vLeft = evt.clientX - elemMove.mouseX + parseInt(elemMove.style.left);
        var vTop = evt.clientY - elemMove.mouseY + parseInt(elemMove.style.top);
        if (!objDlg.bout && (vLeft < 0 
            || vLeft + elemMove.offsetWidth > CtnDlgCtrl.getDocWidth()))
        {
            //elemMove.style.left = vLeft + "px";
        }
        else
        {
            elemMove.style.left = vLeft + "px";
        }
        if (!objDlg.bout && (vTop < 0 
            || vTop + elemMove.offsetHeight > CtnDlgCtrl.getDocHeight()))
        {
	        //elemMove.style.top = vTop + "px";
	    }
	    else
	    {
	        elemMove.style.top = vTop + "px";
	    }
	    elemMove.mouseX = evt.clientX;
	    elemMove.mouseY = evt.clientY;
	}
}

function mouseup_DC(evt)
{
	if (CtnDlgCtrl.elemMove)
	{
	    var elemMove = CtnDlgCtrl.elemMove;
	    var elemDlg = elemMove.elemDlg;
	    CtnDlgCtrl.unbind(document, "mousemove", CtnDlgCtrl.moveDlg);
	    elemDlg.style.left = parseInt(elemMove.style.left) + "px";
	    elemDlg.style.top = parseInt(elemMove.style.top) + "px";
	    elemDlg.style.display = "";

        CtnDlgCtrl.adjustBg(elemDlg);
	    elemDlg.elemBg.style.display = "";
        //调整离窗口的位置
	    elemDlg.winX = parseInt(elemMove.style.left) - document.documentElement.scrollLeft;
        elemDlg.winY = parseInt(elemMove.style.top) - document.documentElement.scrollTop;
	    elemMove.style.display = "none";
        
	    CtnDlgCtrl.elemEvent.style.display = "none";
	    if (elemDlg.object.bresize)
	    {
	        CtnDlgCtrl.adjustBar(elemDlg);
	    }

	    CtnDlgCtrl.elemMove = null;
	}
	if (CtnDlgCtrl.elemBar)
	{
	    var elemResize = CtnDlgCtrl.elemResize;
	    var elemDlg = CtnDlgCtrl.elemBar.elemDlg;
	    CtnDlgCtrl.unbind(document, "mousemove", CtnDlgCtrl.resizeDlg);
	    elemDlg.style.left = parseInt(elemResize.style.left) + "px";
	    elemDlg.style.top = parseInt(elemResize.style.top) + "px";
	    elemDlg.style.width = (elemResize.offsetWidth - 2) + "px";
	    
	    elemDlg.elemBody.style.width = (parseInt(elemDlg.style.width) - elemDlg.lrWidth) + "px";
	    
	    elemDlg.elemBody.style.height = (elemResize.offsetHeight - elemDlg.tbHeight - 2) + "px";
	    elemDlg.style.display = "";
	    CtnDlgCtrl.adjustBg(elemDlg);
	    elemResize.style.display = "none";
		elemDlg.winX = parseInt(elemDlg.style.left) - document.documentElement.scrollLeft;
	    elemDlg.winY = parseInt(elemDlg.style.top) - document.documentElement.scrollTop;
	    CtnDlgCtrl.elemEvent.style.display = "none";
	    //拉伸后，响应事件
	    if(elemDlg.object.onResize)
	    {
	        elemDlg.object.onResize(elemDlg.object);
	    }
	    CtnDlgCtrl.elemBar = null;
	}
	//m_flexibleElem = null;
}

function adjustBg_DC(elemDlg)
{
    if (elemDlg.elemBody.offsetHeight > 0)
    {
        elemDlg.elemIcon.style.height = (elemDlg.elemBody.offsetHeight - 2) + "px";
    }
    elemDlg.elemBg.style.left = parseInt(elemDlg.style.left) + "px";
    elemDlg.elemBg.style.top = parseInt(elemDlg.style.top) + "px";
    elemDlg.elemBg.style.width = elemDlg.offsetWidth + "px";
    elemDlg.elemBg.firstChild.style.height = elemDlg.offsetHeight + "px";
    //elemDlg.parentNode.appendChild(elemDlg);//解决input控件不能输入问题
}

function adjustBar_DC(elemDlg)
{
    var barSize = 2;
    var halfSize = parseInt(barSize / 2);
    var arrBar = elemDlg.arrBar;
    
    var left    = parseInt(elemDlg.style.left);
    var top     = parseInt(elemDlg.style.top);
    var width   = elemDlg.offsetWidth;
    var height  = elemDlg.offsetHeight;
    
    arrBar[0].style.left = (left) + "px";
    arrBar[0].style.top = (top) + "px";
    arrBar[0].style.width = (width) + "px";
    
    arrBar[1].style.left = (left + width - barSize*2) + "px";
    arrBar[1].style.top = (top) + "px";

    arrBar[2].style.left = (left + width - barSize) + "px";
    arrBar[2].style.top = (top) + "px";
    arrBar[2].style.height = (height) + "px";

    arrBar[3].style.left = (left + width - barSize*2) + "px";
    arrBar[3].style.top = (top + height - barSize*2) + "px";

    arrBar[4].style.left = (left) + "px";
    arrBar[4].style.top = (top + height - barSize) + "px";
    arrBar[4].style.width = (width) + "px";

    arrBar[5].style.left = (left) + "px";
    arrBar[5].style.top = (top  + height - barSize*2) + "px";

    arrBar[6].style.left = (left) + "px";
    arrBar[6].style.top = (top) + "px";
    arrBar[6].style.height = (height) + "px";

    arrBar[7].style.left = (left) + "px";
    arrBar[7].style.top = (top) + "px";
}

function resizeDlg_DC(evt)
{   
    if (CtnDlgCtrl.elemBar)
	{
	    var elemBar = CtnDlgCtrl.elemBar;
	    var objDlg = elemBar.elemDlg.object;
	    var elemResize = CtnDlgCtrl.elemResize;
		var pos = CtnDlgCtrl.getMoveXY(evt, elemBar);

        var vLeft = elemBar.arrFlag[0] * pos.x + parseInt(elemResize.style.left);
        var vTop = elemBar.arrFlag[1] * pos.y + parseInt(elemResize.style.top);
        var vWidth = elemBar.arrFlag[2] * pos.x + elemResize.offsetWidth - 2;
        var vHeight = elemBar.arrFlag[3] * pos.y + elemResize.offsetHeight - 2;
        if (vLeft > 0 && vLeft + vWidth < CtnDlgCtrl.getDocWidth()
            && vWidth > objDlg.minwidth)
        {
		    elemResize.style.left = vLeft + "px";
		    elemResize.style.width = vWidth + "px";
		}
		else
		{
		    elemResize.style.left = (vLeft - elemBar.arrFlag[0] * pos.x) + "px";
		    elemResize.style.width = (vWidth - elemBar.arrFlag[2] * pos.x) + "px";
		}
		
		if (vTop >0 && vTop + vHeight < CtnDlgCtrl.getDocHeight()
		    && vHeight > objDlg.minheight)
		{
		    elemResize.style.top = vTop + "px";
		    elemResize.style.height = vHeight + "px";
		}
		else
		{
		    elemResize.style.top = (vTop - elemBar.arrFlag[1] * pos.y) + "px";
		    elemResize.style.height = (vHeight - elemBar.arrFlag[3] * pos.y) + "px";
		}

		CtnDlgCtrl.adjustBar(elemResize);
	}
}

function getDocWidth_DC()
{
    var width = 0;
    if (document.all && width - document.documentElement.clientWidth < 22)
    {
        width = document.documentElement.clientWidth;
    }
    else
    {
        width = Math.max(document.documentElement.clientWidth, document.documentElement.offsetWidth);
        width = Math.max(width, document.body.offsetWidth) - 4;
    }
    return width;
}

function getDocHeight_DC()
{
    var height = Math.max(document.documentElement.clientHeight, document.documentElement.offsetHeight);
    height = Math.max(height, document.body.offsetHeight);
    return height - 4;
}